package com.xjl.service.impl;

import com.xjl.aop.InvokeLog;
import com.xjl.domain.User;
import com.xjl.mapper.UserMapper;
import com.xjl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    @InvokeLog
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    @Transactional //事务回滚，只要报错了，之前的数据库操作也会失效
    public void insertUser() {
        //添加两个用户
        User user1 = new User(null,"小明",15,"南京");
        User user2 = new User(null,"小红",17,"北京");
        userMapper.insertUser(user1);
        System.out.println(1/0);
        userMapper.insertUser(user2);
    }
}
